<div id="pad-wrapper" class="new-user">
	<div class="row-fluid header">
		<h3>编辑标签</h3>
	</div>
	<div class="row-fluid form-wrapper">
		<!-- left column -->
		<div class="span9 with-sidebar">
			<div class="container">
				<form class="new_user_form form-horizontal" action="/knowledge-tag/save" method="post" id="dataForm" enctype="multipart/form-data">
					<input type="hidden" name="id" value="<?php echo $row['tag_id']?>">
					<div class="field-box"></div>
					<div class="control-group form-group span12">
						<label class="control-label" for="banner_name">标签名称:</label>
						<div class="controls col-lg-5">
							<input type="text" class="form-control" id="tag_name" name="tag_name" value="<?php echo $row['tag_name']?>" placeholder="标签名称"/>
						</div>
					</div>
					<div class="control-group form-group span12">
						<label class="control-label" for="t_sort">分类:</label>
						<div class="controls col-lg-5">
								<?php foreach ($categorys as $category):?>
								<input type="checkbox" name="category_id[]" value="<?php echo $category['cate_id']?>" 
                                                                        <?php 
                                                                             foreach ($tags as $tag){
                                                                                if($category['cate_id'] == $tag['category_id'] and $tag['category_tag_status'] == 1):?> checked="checked"<?php endif;}?>/><?php echo $category['cate_name']?>
								<?php endforeach;?>
						</div>
					</div>
                                        <div class="control-group form-group span12">
						<label class="control-label" for="type">类型:</label>
						<div class="controls col-lg-5">
							<select id="type" name="type">
								<option>请选择</option>								
                                                                <option value="1"<?php if($row['tag_type'] == 1) echo "selected" ;?>>分类标签</option>
                                                                <option value="2"<?php if($row['tag_type'] == 2) echo "selected" ;?>>普通标签</option>
							</select>
						</div>
					</div>
					<div class="span12 field-box"></div>
					<div class="control-group form-group span12 actions">
						<label class="control-label" for="" class="control-label"></label>
						<div class="controls col-lg-5">
							<input type="submit" class="btn-glow primary" value="提交" />
						</div>
					</div>
				</form>
			</div>
		</div>
		<!-- side right column -->
		<div class="span3 form-sidebar pull-right">
		</div>
	</div>	
	<script type="text/javascript">
	$(document).ready(function() {

		$('#dataForm').bootstrapValidator({
			message: 'This value is not valid',
			feedbackIcons: {
				valid: 'glyphicon glyphicon-ok',
				invalid: 'glyphicon glyphicon-remove',
				validating: 'glyphicon glyphicon-refresh'
			},
			fields: {
				tag_name: {
					message: '标签名称不符合规则',
					validators: {
						notEmpty: {
							message: '标签名称是必填项，不能为空'
						}
					}
				},
				category_id: {
					message: '标签分类不符合规则',
					validators: {
						notEmpty: {
							message: '标签分类是必填项，不能为空'
						},
						regexp: {
							regexp: /\d/,
							message: '请选择子分类'
						}
					}
				}
			}
		});
		
		$("#change").change(function(e){
			if($(this).val())
			{
				$.ajax({
					url: "/knowledge-tag/ajaxcate",
					type: "post",
					data: {"parent_id":  $(this).val()},
					dataType: "json",
					success: function(res)
					{
						var option = "<option>请选择</option>";
						$.each(res, function(i, val){
							option += "<option value='" +  val["cate_id"]  + "'>";
							option += val["cate_name"];
							option += "</option>";
							
						});
						
						$("#category_id").html(option);
					}
				});
			}
				
		});
		
	});
	</script>
</div>